package com.it.d7_interface_demo;

import java.util.ArrayList;

public class StudentOperatorImpl2 implements StudentOperator {

    @Override
    public void printAllInfo(ArrayList<Student> students) {
        System.out.println("---------全部学生信息如下------------------");

        int femaleCount = 0; // 男生人数
        int maleCount = 0; // 女生人数

        for (int i = 0; i < students.size(); i++) {
            // 获取每项信息
            Student s = students.get(i);
            System.out.println("姓名：" + s.getName() + ",性别：" + s.getSex() + ",成绩：" + s.getScore());

            if (s.getSex() == '男') {
                femaleCount++;
            } else {
                maleCount++;
            }
        }
        System.out.println("男生人数是：" + femaleCount + ",女生人数是：" + maleCount);
        System.out.println("班级总人数是：" + students.size());
        System.out.println("---------------------------");
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        double allScore = 0.0;

        double max = students.get(0).getScore(); // 最高分
        double min = students.get(0).getScore(); // 最低分

        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);

            if (s.getScore() > max) max = s.getScore();

            if (s.getScore() < min) min = s.getScore();

            allScore += s.getScore();
        }
        System.out.println("最高分：" + max);
        System.out.println("最低分：" + min);
        System.out.println("平均分：" + (allScore - max - min) / (students.size() - 2));
    }
}
